home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 26
/
Cream of the Crop 26.iso
/
program
/
tcqbsnip.zip
/
GETARG.BAS
< prev
next >
Wrap
BASIC Source File
|
1997-06-20
|
4KB
|
123 lines
' GETARG.BAS
' by Tika Carr
' October 28, 1996
'
' ExePath$ written by Joe Negron
'
' Donated to the public domain
' No warranties or guarantees are expressed or implied.
'
' Purpose: Returns list of arguements from COMMAND$ to an array.
' REQUIRES QuickBasic 4.5! (Will not work in QBasic)
' (Start QuickBasic with: QB /L QB.QLB)
'
'Description/Instructions:
'
'Parses the COMMAND$ (which holds any parameters passed to the program
'from the command line). Returns the full path and filename of the
'program currently running in the global variable arg$(0). arg$(1) to
'arg$(85) holds each the command line parameters passed. Simply look for
'one of the arrays to be blank (ie. arg$(x)="") for the end of the list.
'if arg$(1)="" then there were no parameters passed to the program (here
'you would have it print a usage or help screen).
'To test this program:
'
'Set COMMAND$ for something like: test /sw1 /er /x -s Macro
'Then run the program below. After that, try passing no paramteres by
'setting COMMAND$ to "" or nothing. This is done in the IDE from the RUN
'menu, Modify COMMAND$ option.
DECLARE SUB GetArg ()
DECLARE FUNCTION ExePath$ ()
'$INCLUDE: 'qb.bi'
DEFINT A-Z
DIM SHARED arg$(0 TO 85)
CLS
GetArg
PRINT "The program running is: "; arg$(0)
'Note that the above line may give the full path and file name to the
'QuickBasic 4.5 IDE program if you don't compile this. But when put in
'A library and it is compiled, it will show the correct executable and
'path.
IF arg$(1) = "" THEN
PRINT "You didn't pass any parameters"
ELSE
i = 1
DO UNTIL arg$(i) = ""
PRINT "Parameter #"; i; " is: "; arg$(i)
i = i + 1
LOOP
END IF
PRINT i - 1; " parameters were found, excluding the name of the program."
'EXEPATH$.BAS: Gets the path and filename of the executable running.
' by Joe Negron. Function name changed by Tika Carr.
'-----------------------------------------------------------------------
'Function Description:
'
'Uses DOS ISR 21H, Function 51H (Get PSP Address) to return the
'name of the currently executing program. Note that this FUNCTION
'requires DOS 3.0 or >.
'-----------------------------------------------------------------------
'**** TEST Program ****
'E$ = ExePath$
'PRINT E$
'-----------------------------------------------------------------------
FUNCTION ExePath$ STATIC
DIM Regs AS RegType 'Allocate space for TYPE
' RegType
Regs.ax = &H5100 'DOS function 51h
Interrupt &H21, Regs, Regs ' Get PSP Address
DEF SEG = Regs.bx 'Regs.bx returns PSP sgmnt.
EnvSeg% = PEEK(&H2C) + PEEK(&H2D) * 256 'Get environment address
DEF SEG = EnvSeg% 'Set environment address
DO
Byte% = PEEK(Offset%) 'Take a byte
IF Byte% = 0 THEN 'Items are ASCIIZ
Count% = Count% + 1 ' terminated
IF Count% AND EXEFlag% THEN 'EXE also ASCIIZ terminated
EXIT DO 'Exit at the end
ELSEIF Count% = 2 THEN 'Last entry in env. is
EXEFlag% = -1 ' terminated with two
Offset% = Offset% + 2 ' NULs. Two bytes ahead
END IF ' is the EXE file name.
ELSE 'If Byte% <> 0, reset
Count% = 0 ' zero counter
IF EXEFlag% THEN 'If EXE name found,
Temp$ = Temp$ + CHR$(Byte%) ' build string
END IF
END IF
Offset% = Offset% + 1 'To grab next byte...
LOOP 'Do it again
DEF SEG 'Reset default segment
ExePath$ = Temp$ 'Return value
Temp$ = "" 'Clean up
END FUNCTION
SUB GetArg
arg$(0) = ExePath$
IF COMMAND$ = "" THEN EXIT SUB
i = 1: j = 1
DO UNTIL i >= LEN(COMMAND$)
WHILE MID$(COMMAND$, i, 1) <> " " AND MID$(COMMAND$, i, 1) <> ""
arg$(j) = arg$(j) + MID$(COMMAND$, i, 1)
i = i + 1
WEND
i = i + 1: j = j + 1
LOOP
END SUB